﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using ModuleDALCore;

namespace DAL
{
	public class LOAIRANGDAO:DALBase
	{
		public LOAIRANGDAO()

		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPLOAIRANG"; }
			set { _SpName = value; }
		}
		public List<LOAIRANG> GetListLRs()
		{
			List<LOAIRANG> lr = new List<LOAIRANG>();
			dt = new DataTable();

			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new LOAIRANG(), null), ConvertClassToArray.GetValues(new LOAIRANG(), 0));
				lr = (List<LOAIRANG>) ConvertDatatableToList.ConvertTo<LOAIRANG>(dt);
			}

			catch
			{
				return null; //throw new Exception("Không thể tạo danh sách loại răng!");
			}

			return lr;
		}

		public DataTable GetListLR()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new LOAIRANG(), null), ConvertClassToArray.GetValues(new LOAIRANG(), 0));
				return dt;
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list LR"); }
		}
		public String CreatenewId()
		{
			try
			{
				return "LR" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new LOAIRANG(), null), ConvertClassToArray.GetValues(new LOAIRANG(), 1));

			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't Create new LR"); }
		}
		public bool INSERT(LOAIRANG lr)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(lr, null), ConvertClassToArray.GetValues(lr, 2)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Insert new LR"); }
		}
		public bool UPDATE(LOAIRANG lr)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(lr, null), ConvertClassToArray.GetValues(lr, 3)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Update  LR"); }
		}
		public bool DELETE(LOAIRANG lr)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(lr, null), ConvertClassToArray.GetValues(lr, 4)) == 1);

			}
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Delete  LR"); }
		}
	}
}
